package com.bcsp.xml;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.List;

public class Test3 {
    public static void main(String[] args) throws Exception {
        //使用dom4j
        String path = Test3.class.getClassLoader().getResource("a.xml").getPath();
        SAXReader reader = new SAXReader();
        Document document = reader.read(new File(path));
        //获取根节点
        Element root = document.getRootElement();
        //获取子元素节点
        List<Element> stus = root.elements("student");
        for (Element stu : stus){
            System.out.println(stu.getName());
            System.out.println(stu.attribute("name").getValue()+","
                    +stu.attribute("age").getValue()+","
                    +stu.attribute("gender").getValue());
        }
    }
}
